package cc.wsyw126.java.nowcoder.offernet;

/**
 * Created by dp on 17/3/25.
 */

import java.util.Scanner;

public class net2 {
    private static int count = 0;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        String s1 = sc.nextLine();
        int n = Integer.valueOf(s1);
        StringBuilder sb = new StringBuilder(s);
        doHandle(sb, 0, sb.length(), n);
        System.out.println(count);

    }

    private static void doHandle(StringBuilder sb, int i, int length, int n) {
        if (i == length) {
            if (Integer.valueOf(sb.toString()) % n == 0) {
                count++;
                return;
            }
            return;
        }


        while (sb.charAt(i) != 'X') {
            i++;
            if (i == length) {
                doHandle(sb, i, length, n);
                return;
            }
        }

        for (int j = 0; j < 10; j++) {
            sb.replace(i, i + 1, j + "");
            doHandle(sb, i, length, n);
        }
    }
}